#include "VPRWidget.h"


#ifndef UNDER_CE


#if 0

VPRWidget::VPRWidget(void) :
    _select(false)
{
}

VPRWidget::VPRWidget(VContainer* parent) :
    VWidget(parent)
{

}


VPRWidget::~VPRWidget(void)
{
}

bool VPRWidget::inArea(int x, int y)
{
    static GLuint selectBuf[PICKING_BUFFSIZE] = {0};
    static GLint viewport[4] = {0};
    static GLuint* ptr = NULL;
    GLint hits = 0;

    glSelectBuffer(PICKING_BUFFSIZE, selectBuf);
    glGetIntegerv(GL_VIEWPORT, viewport);

    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(VMain::getIncreament(INC_PICKING_NAME));

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    {
        glLoadIdentity();

        // 定义一个以光标为中心的PICKING_ACCURACY^2拾取区域
        // 必须对鼠标y坐标求反，从屏幕坐标系转换成世界坐标系
        gluPickMatrix(x, VIEWPORT_HEIGHT - y,
                      PICKING_ACCURACY, PICKING_ACCURACY, viewport);
        glOrtho(0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0,
                -ORTHO_MATRIX_DEPTH, ORTHO_MATRIX_DEPTH);

        glMatrixMode(GL_MODELVIEW);

        setSelect();
        this->render();
        setRender();

        glMatrixMode(GL_PROJECTION);
    }
    glPopMatrix();

    hits = glRenderMode(GL_RENDER);

    glMatrixMode(GL_MODELVIEW);
    glPopName();

    if (hits > 0)
    {
        return true;
    }

    return false;
}


bool VPRWidget::render() const
{
    if (!VWidget::render())
    {
        return false;
    }

    // donot do any render.
    if (_select)
    {
        glLoadName(VMain::getIncreament(INC_PICKING_NAME));
    }

    return true;
}

void VPRWidget::setSelect()
{
    _select = true;
}

void VPRWidget::setRender()
{
    _select = false;
}


#endif

#endif  // UNDER_CE